//
//  MAPYHomeViewController.swift
//  Mars Proxy
//
//  Created by PowerfullClean on 2023/10/16.
//

import UIKit

class MAPYHomeViewController: MAPYBaseCollectionViewController {

    override func viewDidLoad() {
        super.viewDidLoad()
        MAPYManager.mapy_manager.mapy_configVpnAuth()
        MAPYManager.mapy_manager.mapy_configLocManager()
        MAPYManager.mapy_manager.mapy_requesAuthLocation()
    }
    // MARK: - mapy action
    override func viewWillAppear(_ animated: Bool) {
        super.viewWillAppear(animated)
        mapy_collectionView.reloadData()
    }
    override func mapy_collectionViews() {
        view.addSubview(mapy_bottomView)
        super.mapy_collectionViews()
        view.addSubview(mapy_navView)
        mapy_collectionView.snp.makeConstraints { make in
            make.bottom.width.left.equalToSuperview()
            make.top.equalTo(mapy_navView.snp.bottom)
        }
        mapy_bottomView.snp.makeConstraints { make in
            make.bottom.left.width.equalToSuperview()
            make.height.equalTo(mapy_SCREEN_HEIGHT/2.0)
        }
        mapy_collectionView.register(MAPYHomeConnectCell.classForCoder(), forCellWithReuseIdentifier: MAPYHomeConnectCell.mapy_viewToString)
        mapy_collectionView.dataSource = self
        mapy_collectionView.delegate = self
        
    }
    // MARK: - mapy lazy
    override func mapy_baseBgName() -> String? {
        return "mapy_home_bg"
    }
    lazy var mapy_navView: MAPYHomeNavView = {
        let mapy_navView = MAPYHomeNavView()
        return mapy_navView
    }()
    lazy var mapy_bottomView: UIImageView = {
        let mapy_bottomView = UIImageView(image: UIImage(named: "mapy_home_bottom"))
        return mapy_bottomView
    }()
}

extension MAPYHomeViewController: UICollectionViewDataSource, UICollectionViewDelegateFlowLayout {
    func collectionView(_ collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int {
        return 1
    }
    func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell {
        let mapy_cell = collectionView.dequeueReusableCell(withReuseIdentifier: MAPYHomeConnectCell.mapy_viewToString, for: indexPath) as! MAPYHomeConnectCell
        mapy_cell.mapy_reloadSpeedValue()
        mapy_cell.mapy_reloadIpShow()
        return mapy_cell
    }
    func collectionView(_ collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout, sizeForItemAt indexPath: IndexPath) -> CGSize {
        return CGSize(width: mapy_SCREEN_WIDTH, height: 500+163)
    }
}
